﻿using CPPEI.Coolzon.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Launcher
{
    [XConfigRoot("Environment")]
    public class CZEnvironment
    {
        private static Version _version;
        /// <summary>
        /// 获得主程序的版本号
        /// </summary>
        public static Version Version
        {
            get
            {
                if (_version == null)
                {
                    _version = typeof(CZEnvironment).Assembly.GetName().Version;
                }
                return _version;
            }
        }

        /// <summary>
        /// 版本信息-.-.-
        /// </summary>
        public static string Version3
        {
            get
            {
                return Version.ToString(3);
            }
        }


        private static CZEnvironment s_instance;
        public static CZEnvironment Instance
        {
            get
            {
                if (s_instance == null)
                {
                    s_instance = new CZEnvironment();
                }
                return s_instance;
            }
        }

        /// <summary>
        /// 更新服务器的地址信息
        /// </summary>
        [XConfig("Host", false)]
        public Coolzon.Configuration.Client.ServiceConfig ServiceConfig { get; private set; }

        #region static methods

        /// <summary>
        /// 获取日志目录
        /// </summary>
        /// <returns></returns>
        public static string GetLogDirectory()
        {
            return string.Format("{0}\\Coolzon\\Logs\\v{1}\\Launcher\\",
                Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                Version3);
        }

        /// <summary>
        /// 获取Environment.xml文件的地址
        /// </summary>
        /// <returns></returns>
        public static string GetEnvironmentFilePath()
        {
            return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Config\\Environment.xml"); ;
        }

        #endregion
    }
}
